package com.boot.stream;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Objects;


@SpringBootApplication
public class StreamApplication {

    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext context = SpringApplication.run(StreamApplication.class, args);
        Test bean = context.getBean(Test.class);
        String app = context.getEnvironment().getProperty("app", String.class);
        int supplier1min = Objects.requireNonNull(context.getEnvironment().getProperty("supplier1.min", Integer.class));
        int supplier1max = Objects.requireNonNull(context.getEnvironment().getProperty("supplier1.max", Integer.class));
        int supplier2min = Objects.requireNonNull(context.getEnvironment().getProperty("supplier2.min", Integer.class));
        int supplier2max = Objects.requireNonNull(context.getEnvironment().getProperty("supplier2.max", Integer.class));
        Thread.sleep(5000);

        //        new Thread(() -> {
        //            for (int i = 0; i <= 10; i++) {
        //                bean.streamTest(app, i);
        //                try {
        //                    Thread.sleep(1000);
        //                } catch (InterruptedException e) {
        //                    e.printStackTrace();
        //                }
        //            }
        //        }).start();

        new Thread(() -> {
            for (int i = supplier1min; i <= supplier1max; i++) {
                bean.streamTest1(app, i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(() -> {
            for (int i = supplier2min; i <= supplier2max; i++) {
                bean.streamTest2(app, i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

}
